package net.hn.hnms.biz.energy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.hn.hnms.biz.energy.domain.WaterSettlement;
import net.hn.hnms.biz.energy.request.WaterSettlementReq;
import net.hn.hnms.biz.energy.vo.WaterSettlementVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

public interface WaterSettlementMapper extends BaseMapper<WaterSettlement> {
    @Update("<script>" +
            " update  water_settlement set  del_flag = '1' " +
            " where water_settle_id in" +
            " <foreach collection=\"list\" item=\"value\" separator=\",\" open=\"(\" close=\")\">\n" +
            "#{value}" +
            "</foreach>" +
            "</script>")
    void updateDeleteByIds(@Param("list") List<String> list);

    @Select("<script>" +
            " select ws.water_settle_id waterSettleId,ws.water_supply_company_id waterSupplyCompanyId,wsc.water_supply_company_name waterSupplyCompanyName,ws.water_place_id waterPlaceId,wpp.water_place_name waterPlaceName,ws.water_unit_price waterUnitPrice, " +
            " ws.last_meter_date lastMeterDate,ws.last_meter_value lastMeterValue,ws.meter_value meterValue,ws.meter_date meterDate,ws.water_consumption waterConsumption,ws.remark remark,ws.create_time createTime,wpp.water_unit_category from water_settlement ws LEFT JOIN water_supply_company wsc on ws.water_supply_company_id = wsc.water_supply_company_id " +
            " LEFT JOIN water_place_price wpp on ws.water_place_id = wpp.water_place_id " +
            " where ws.del_flag = '0' " +
            " <if test='query.mineCode != null and query.mineCode != \"\" '> "+
            " and ws.mine_code = #{query.mineCode} " +
            " </if>"+
            " <if test='query.waterPlaceId != null and query.waterPlaceId != \"\" '>"+
            " and ws.water_place_id = #{query.waterPlaceId} " +
            " </if>"+
            " <if test='query.waterPlaceName != null and query.waterPlaceName != \"\" '>"+
            " and wpp.water_place_name LIKE CONCAT('%', #{query.waterPlaceName}, '%') " +
            " </if>"+

            " <if test='query.waterUnitCategory != null and query.waterUnitCategory != \"\" '> "+
            " and wpp.water_unit_category = #{query.waterUnitCategory} " +
            " </if>"+

            " order by ws.create_time desc</script>")
    Page<WaterSettlementVo> selectPageList(Page<Object> build, @Param("query") WaterSettlementReq waterSettlementReq);

    @Select("<script> select sum(water_consumption) from water_settlement where del_flag='0' and mine_code=#{mineCode} </script>")
    BigDecimal getWaterSettlementByMineCode(@Param("mineCode") String mineCode);
}
